<?php
function printzonedropdown($selected, $dbh) {
	$result = mysql_query("SELECT zonename FROM `leagues_daily` where leagueid != 0 group BY zonename", $dbh);
	$i = 0;
	echo "<SELECT NAME=\"zoneid\" ONCHANGE=\"form.leagueid.value = '0'; form.submit()\">\n";
	if ($selected) echo "\t<OPTION VALUE=\"$i\">all zones</OPTION>\n";
	else echo "\t<OPTION VALUE=\"$i\">all zones</OPTION>\n";
	while ($zone = mysql_fetch_array($result)) {
		$i++;
		echo "\t<OPTION VALUE=\"$i\"";
		if ($i == $selected) echo "SELECTED";
		echo ">" . $zone[0] . "</OPTION>\n";
	}
	echo "</SELECT>\n";
}

function printleaguedropdown($selected, $zoneid, $alltext, $dbh) {
	$result = "";
	if ($zoneid) {
		$zones = mysql_query("SELECT zonename FROM `leagues_daily` where leagueid != 0 group BY zonename", $dbh);
		$zonelist = array('Global');
		while ($zone = mysql_fetch_array($zones)) {
			$zonelist[] = $zone[0];
		}
		$result = mysql_query("SELECT * FROM leagues_daily WHERE leagueid != 0 AND leagueid != 255 AND zonename = '{$zonelist[$zoneid]}' ORDER BY ShortName", $dbh);
	}
	else $result = mysql_query("SELECT * FROM leagues_daily WHERE leagueid != 0 AND leagueid != 255 ORDER BY ShortName", $dbh);
#	echo "<SELECT NAME=\"leagueid\" ONCHANGE=\"maptrick.regionid.value = '0'; maptrick.submit()\">\n";
	echo "<SELECT NAME=\"leagueid\" ONCHANGE=\"form.submit()\">\n";
	echo "\t<OPTION VALUE=\"0\">$alltext</OPTION>\n";
	echo "\t<OPTION>               </OPTION>\n";
	while ($league = mysql_fetch_array($result)) {
		echo "\t<OPTION VALUE=\"$league[0]\"";
		if ($league[0] == $selected) echo "SELECTED";
		echo ">{$league['ShortName']}</OPTION>\n";
	}
	echo "</SELECT>\n";
}

function printregiondropdown($selected, $leagueid, $dbh) {
	$result = mysql_query("SELECT * FROM regions where leagueid=$leagueid ORDER BY regionname", $dbh);
	echo "<select name=\"regionid\" onchange=\"form.submit()\">\n";
	echo "\t<OPTION VALUE=\"0\">Pick region...</OPTION>\n";
	echo "\t<OPTION>               </OPTION>\n";
	while ($region = mysql_fetch_array($result)) {
		echo "\t<OPTION VALUE=\"$region[0]\"";
		if ($region[0] == $selected) echo "selected=\"selected\"";
		echo ">{$region[1]}</OPTION>\n";
	}
	echo "</select>\n";
}

function printactiondropdown($selected, $dbh) {
	$actions = array(
		0 => "Show Bots",
		1 => "Show Supporters"
	);
	echo "<SELECT NAME=\"action\" ONCHANGE=\"form.submit()\">\n";
	foreach (array_keys($actions) as $action) {
		echo "\t<OPTION VALUE=\"$action\"";
		if ($action == $selected) echo "SELECTED";
		echo ">{$actions[$action]}</OPTION>\n";
	}
	echo "</SELECT>\n";
}

function printgenericdropdown($name, $selected, $default, $options, $optionstyles = array()) {
	$onchange = "";
	if ($name === "allianceid") $onchange = "form.leagueid.value = '0'; form.zoneid.value = '0'; ";
	echo "<select name=\"$name\" onchange=\"{$onchange}form.submit()\">\n";
	if ($default !== "") {
		echo "\t<option value=\"\">$default</option>\n";
		echo "\t<option></option>\n";
	}
	foreach (array_keys($options) as $i) {
		echo "\t<option value=\"$i\"";
		if (count($optionstyles) == count($options)) echo " style=\"{$optionstyles[$i]}\"";
		if ($i == $selected) echo " selected=\"selected\"";
		echo ">{$options[$i]}</option>\n";
	}
	echo "</select>\n";
}
?>
